package com.ljc.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;

/**
 * Websocket配置
 * @Author: ljc
 * @Date:Created in 15:22 2022/2/17
 */
@EnableAsync
@Configuration
@EnableWebSocketMessageBroker//表示开启使用Stomp协议传输基于代理的信息
public class Wsconfig implements WebSocketMessageBrokerConfigurer {
    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        registry.addEndpoint("/websocket")//表示注册一个端点,websocket的访问端点
                .withSockJS();//
    }
   //配置消息的默认代理
    @Override
    public void configureMessageBroker(MessageBrokerRegistry registry) {
        registry.enableSimpleBroker("/user/","/topic/");//推送消息的前缀
        registry.setApplicationDestinationPrefixes("/app");
    }
}

